<template>
  <div class="myv">
    <div class="headera">
      <div class="img">
        <img src="../assets/img/fanhui.png" alt="" />
      </div>
      <div class="title">个人中心</div>
    </div>

    <div class="userz" v-if="!flag">
      <div class="img">
        <img
          src="https://www.suoyiren.com/uc_server/images/noavatar_middle.gif?ts=1640112318"
          alt=""
        />
      </div>
      <div class="bottom">
        <div class="word">
          <p>buD219855 <i>LV.1</i></p>
          <span>UID:1082263 积分:2</span>
        </div>
        <div class="box">
          <div class="item">
            <p>0</p>
            <span>帖子</span>
          </div>
          <div class="item">
            <p>{{this.szList?this.szList[0].length:'0'}}</p>
            <span>收藏</span>
          </div>
          <div class="item">
            <p>0</p>
            <span>粉丝</span>
          </div>
        </div>
      </div>
    </div>

    <div class="userz" v-if="flag">
      <div class="img" @click="gos">
        <img
          src="https://www.suoyiren.com/uc_server/images/noavatar_middle.gif?ts=1640112318"
          alt=""
        />
      </div>
      <div class="bottom">
        <div class="word">
          <p>请登录 </p>
          <!-- <span>UID:1082263 积分:2</span> -->
        </div>
        <div class="box">
          <div class="item">
            <p>0</p>
            <span>帖子</span>
          </div>
          <div class="item">
            <p>0</p>
            <span>收藏</span>
          </div>
          <div class="item">
            <p>0</p>
            <span>粉丝</span>
          </div>
        </div>
      </div>
    </div>

    <div class="box">
      <div class="items" v-for="(item, index) in imgy" :key="index">
        <div class="img" @click="joing(item.id)">
          <img :src="item.img" alt="" />
        </div>
        <div class="word">{{ item.name }}</div>
      </div>
    </div>

    <div class="main">
      <div class="items" v-for="(item, index) in imgp" :key="index">
        <div class="img">
          <img :src="item.img" alt="" />
        </div>
        <div class="word">{{ item.name }}</div>
        <div class="fuhao">
          <img src="../assets/img/fanhui2.png" alt="" />
        </div>
      </div>
    </div>

    <div class="esc" @click="esc">退出登录</div>
    <div class="duo"></div>

    <div class="footer">
      <ul>
        <router-link tag="li" to="/home">
          <a>
            <div class="img">
              <img src="../assets/img/shouye.png" alt="" />
            </div>
            <div class="word">
              <p>首页</p>
            </div>
          </a>
        </router-link>
        <router-link tag="li" to="/talk">
          <a>
            <div class="img">
              <img src="../assets/img/taolun.png" alt="" />
            </div>
            <div class="word">
              <p>交流</p>
            </div>
          </a>
        </router-link>
        <router-link tag="li" to="/release">
          <a>
            <div class="img">
              <img src="../assets/img/fabulow.png" alt="" />
            </div>
            <div class="word">
              <p>发布</p>
            </div>
          </a>
        </router-link>
        <router-link tag="li" to="/find">
          <a>
            <div class="img">
              <img src="../assets/img/quan.png" alt="" />
            </div>
            <div class="word">
              <p>发现</p>
            </div>
          </a>
        </router-link>
        <router-link tag="li" to="/my">
          <a>
            <div class="img">
              <img src="../assets/img/wde1.png" alt="" />
            </div>
            <div class="word">
              <p class="con">我的</p>
            </div>
          </a>
        </router-link>
      </ul>
    </div>
  </div>
</template>

<script>
import { getimgy, getimgp } from "../api/my";
export default {
  data() {
    return {
      imgy: null,
      imgp: null,
      flag:true,
      szList:null,
    };
  },
  methods: {
    //退出登录
    esc() {
      window.localStorage.clear();
      this.$toast("退出成功");
      this.$router.push("/home");
    },
    //进入我的收藏或我的帖子
    joing(id){
      if(id==2){
        this.$router.push("/myposting");
      }else if(id==3){
        this.$router.push("/collection");
      }
    },
    //登录
    gos(){
      this.$router.push('/login');
      this.flag = false;
      window.localStorage.setItem('login',this.flag);
    }
  },
  created() {
    getimgy().then((data) => {
      this.imgy = data.imgy;
    });
    getimgp().then((data) => {
      this.imgp = data.imgp;
    });
    
  },
  mounted(){
    this.flag = window.localStorage.getItem('login')?false:true;
    console.log(this.flag);
    // this.szList = window.localStorage.getItem('shuju');
    // console.log(this.szList);
  }
};
</script>

<style lang="scss" scoped>
.myv {
  background-color: #f3f3f3;
  .headera {
    display: flex;
    justify-content: flex-start;
    padding: 10px;
    background: #53bcf5;
    height: 130px;
    .img {
      width: 20px;
      height: 20px;
      margin-top: 4px;
      img {
        width: 100%;
      }
    }
    .title {
      font-size: 18px;
      font-weight: 400;
      color: #fff;
      flex: 1;
      text-align: center;
    }
  }
  .userz {
    display: flex;
    padding: 10px;
    background: #fff;
    background-image: url(../assets/img/mybg.webp);
    background-size: 100%;
    width: 88%;
    margin: auto;
    margin-top: -50px;
    flex-direction: column;
    border-radius: 16px;
    .img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      background: #e6e6e6;
      overflow: hidden;
      margin-top: -35px;
      img {
        width: 100%;
      }
    }
    .word {
      padding-top: 10px;
      p {
        width: 120px;
        margin-top: 4px;
        i {
          font-style: normal;
          background: #53bcf5;
          color: #fff;
          font-size: 12px;
          padding: 2px;
          border-radius: 6px;
        }
      }
      span {
        display: block;
        margin-top: 20px;
        font-size: 12px;
        color: #999;
      }
    }
    .bottom {
      display: flex;
      justify-content: space-around;
      .box {
        display: flex;
        align-items: center;
        text-align: center;
        justify-content: space-around;
        .item {
          p {
            padding: 0 20px;
            color: #ff9900;
            height: 24px;
            border-right: 1px solid #999;
          }
          &:last-child {
            p {
              border: none;
            }
          }
          span {
            color: #bfbebd;
            font-size: 12px;
          }
        }
      }
    }
  }
  .box {
    width: 88%;
    display: flex;
    flex-wrap: wrap;
    margin: auto;
    margin-top: 20px;
    padding: 10px;
    background: #fff;
    border-radius: 16px;
    .items {
      display: flex;
      width: 25%;
      align-items: center;
      flex-direction: column;
      box-sizing: border-box;
      padding: 10px 0;
      .img {
        width: 32px;
        height: 32px;
        img {
          width: 100%;
        }
      }
      .word {
        padding-top: 10px;
        font-size: 14px;
      }
    }
  }
  .main {
    background: #fff;
    width: 88%;
    padding: 0 10px;
    margin: auto;
    margin-top: 10px;
    border-radius: 16px;
    .items {
      display: flex;
      height: 46px;
      align-items: center;
      border-bottom: 1px solid #bfbebd;
      &:last-child {
        border: none;
      }
      .img {
        width: 23px;
        height: 23px;
        img {
          width: 100%;
        }
      }
      .word {
        flex: 1;
        margin-left: 15px;
      }
      .fuhao {
        margin-right: 4px;
        color: #e6e6e6;
        width: 19px;
        height: 24px;
        img {
          width: 100%;
        }
      }
    }
  }
  .esc {
    background: #53bcf5;
    width: 88%;
    margin: auto;
    color: #fff;
    font-size: 18px;
    border-radius: 16px;
    padding: 0 10px;
    text-align: center;
    height: 48px;
    line-height: 48px;
    margin-top: 10px;
  }
  .duo {
    height: 60px;
  }
  .footer {
    background: #fff;
    width: 100%;
    position: fixed;
    bottom: 0;
    left: 0;
    ul {
      display: flex;
      height: 40px;
      li {
        flex: 1;
        a {
          display: flex;
          flex-direction: column;
          align-items: center;
          .img {
            width: 24px;
            height: 24px;
            img {
              width: 100%;
            }
            &.con {
              transform: rotateX(180deg);
            }
          }
          .word {
            p {
              color: #999;
              font-size: 12px;
              &.con {
                color: #45dfe7;
              }
            }
          }
          .imgz {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background: #53bcf5;
            margin-top: -26px;
            img {
              width: 24px;
              height: 24px;
              position: absolute;
              left: 0;
              top: -14px;
              right: 0;
              bottom: 0;
              margin: 0 auto;
            }
          }
        }
      }
    }
  }
}
</style>
